//
//  SISSPriceMessageAnnotationView.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/11/30.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSPriceMessageAnnotationView.h"

@interface SISSPriceMessageAnnotationView ()

@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UILabel *subTitleLabel;

@end
@implementation SISSPriceMessageAnnotationView

- (id)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]) {
        [self setBounds:CGRectMake(0.f, 0.f, 120, 36)];
        [self setContentView];
    }
    return self;
}

- (void)setContentView {
    
//    UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"地图bg1"]];
    self.layer.cornerRadius = 8;
    self.layer.borderColor = [UIColor orangeColor].CGColor;
    self.layer.borderWidth = 1;
    self.layer.masksToBounds = YES;
    self.backgroundColor = [UIColor whiteColor];
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 8, CGRectGetWidth(self.frame), 12)];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = FONT(10);
    self.titleLabel.textColor = MAIN_TEXT_COLOR;
    [self addSubview:self.titleLabel];
    
    self.subTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame), CGRectGetWidth(self.frame), 12)];
    self.subTitleLabel.textAlignment = NSTextAlignmentCenter;
    self.subTitleLabel.font = FONT(8);
    self.subTitleLabel.textColor = MAIN_TEXT_COLOR;
    [self addSubview:self.subTitleLabel];
    
}

- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleLabel.text = title;
}

- (void)setBuildInfoModel:(SISSMapBuildInfoModel *)buildInfoModel {
    _buildInfoModel = buildInfoModel;
    if (self.isSell) {
        if (buildInfoModel.sellRingRatio.length > 0 && [[buildInfoModel.sellRingRatio substringToIndex:1] isEqualToString:@"-"]) {
            NSString *firstStr = [NSString stringWithFormat:@"%@:%@",buildInfoModel.btype,buildInfoModel.sellPrice];
            NSString *sellRingRatio = [NSString stringWithFormat:@"%@↓",[buildInfoModel.sellRingRatio substringFromIndex:1]];
            NSString *str = [NSString stringWithFormat:@"%@(%@)",firstStr,sellRingRatio];
            NSMutableAttributedString *attriStrM = [[NSMutableAttributedString alloc] initWithString:str];
            NSRange range1 = [str rangeOfString:firstStr];
            [attriStrM addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range1];
            NSRange range2 = [str rangeOfString:sellRingRatio];
            [attriStrM addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:range2];
            self.subTitleLabel.attributedText = attriStrM;
        }  else if (buildInfoModel.sellRingRatio.length == 0 || [buildInfoModel.sellRingRatio integerValue] == 0) {
            
            NSString *firstStr = [NSString stringWithFormat:@"%@:%@",buildInfoModel.btype,buildInfoModel.sellPrice];
            NSString *sellRingRatio = @"持平";
            NSString *str = [NSString stringWithFormat:@"%@(%@)",firstStr,sellRingRatio];
            NSMutableAttributedString *attriStrM = [[NSMutableAttributedString alloc] initWithString:str];
            NSRange range1 = [str rangeOfString:firstStr];
            [attriStrM addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range1];
            NSRange range2 = [str rangeOfString:sellRingRatio];
            [attriStrM addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:range2];
            self.subTitleLabel.attributedText = attriStrM;
        } else {
            NSString *firstStr = [NSString stringWithFormat:@"%@:%@",buildInfoModel.btype,buildInfoModel.sellPrice];
            NSString *sellRingRatio = [NSString stringWithFormat:@"%@↑",buildInfoModel.sellRingRatio];
            NSString *str = [NSString stringWithFormat:@"%@(%@)",firstStr,sellRingRatio];
            NSMutableAttributedString *attriStrM = [[NSMutableAttributedString alloc] initWithString:str];
            NSRange range1 = [str rangeOfString:firstStr];
            [attriStrM addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range1];
            NSRange range2 = [str rangeOfString:sellRingRatio];
            [attriStrM addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:range2];
            self.subTitleLabel.attributedText = attriStrM;
        }
    } else {
        if (buildInfoModel.rentRingRatio.length > 0 && [[buildInfoModel.rentRingRatio substringToIndex:1] isEqualToString:@"-"]) {
            
            NSString *sellRingRatio = [NSString stringWithFormat:@"%@↓",[buildInfoModel.rentRingRatio substringFromIndex:1]];
            NSString *str = [NSString stringWithFormat:@"%@(%@)",buildInfoModel.rentPrice,sellRingRatio];
            NSMutableAttributedString *attriStrM = [[NSMutableAttributedString alloc] initWithString:str];
            NSRange range1 = [str rangeOfString:buildInfoModel.rentPrice];
            [attriStrM addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range1];
            NSRange range2 = [str rangeOfString:sellRingRatio];
            [attriStrM addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:range2];
            self.subTitleLabel.attributedText = attriStrM;
        }  else if (buildInfoModel.rentRingRatio.length == 0 || [buildInfoModel.rentRingRatio integerValue] == 0) {
            
            NSString *sellRingRatio = @"持平";
            NSString *str = [NSString stringWithFormat:@"%@(%@)",buildInfoModel.rentPrice,sellRingRatio];
            NSMutableAttributedString *attriStrM = [[NSMutableAttributedString alloc] initWithString:str];
            NSRange range1 = [str rangeOfString:buildInfoModel.rentPrice];
            [attriStrM addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range1];
            NSRange range2 = [str rangeOfString:sellRingRatio];
            [attriStrM addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:range2];
            self.subTitleLabel.attributedText = attriStrM;
        } else {

            NSString *sellRingRatio = [NSString stringWithFormat:@"%@↑",buildInfoModel.rentRingRatio];
            NSString *str = [NSString stringWithFormat:@"%@(%@)",buildInfoModel.rentPrice,sellRingRatio];
            NSMutableAttributedString *attriStrM = [[NSMutableAttributedString alloc] initWithString:str];
            NSRange range1 = [str rangeOfString:buildInfoModel.rentPrice];
            [attriStrM addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range1];
            NSRange range2 = [str rangeOfString:sellRingRatio];
            [attriStrM addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:range2];
            self.subTitleLabel.attributedText = attriStrM;
        }
    }
    
}



@end
